<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改产品入库')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-income-edit" th:object="${wmsProductIncome}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">产品ID：</label>
                    <div class="col-sm-8">
                        <input name="productId" th:field="*{productId}" class="form-control" type="text" readonly="readonly" id="ProductId" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">产品名称：</label>
                    <div class="col-sm-8">
                        <input name="name" th:field="*{name}" class="form-control" type="text" readonly="readonly" id="ProductName" onclick="selectProductInfo()" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">规格/型号：</label>
                    <div class="col-sm-8">
                        <input name="model" th:field="*{model}" class="form-control" type="text" readonly="readonly" id="ProductModel" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">单价：</label>
                    <div class="col-sm-8">
                        <input name="signalPrice" th:field="*{signalPrice}" class="form-control" type="text" id="signalPrice" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">数量：</label>
                    <div class="col-sm-8">
                        <input name="num" th:field="*{num}" class="form-control" type="text" id="num"  required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">单位：</label>
                    <div class="col-sm-8">
                        <select name="unitName" class="form-control"  required>
                            <option th:each="name : ${uniteNames}" th:text="${name}" th:value="${name}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">金额：</label>
                    <div class="col-sm-8">
                        <input name="totalPrice" th:field="*{totalPrice}" class="form-control" type="text" readonly="readonly" id="totalPrice" onclick="computedProductPrice()" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">创建时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="createtime" th:value="${#dates.format(wmsProductIncome.createtime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">状态：</label>
                    <div class="col-sm-8">
                        <input name="statusInfo" th:field="*{statusInfo}" class="form-control" type="text" readonly="readonly" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <textarea name="common" class="form-control">[[*{common}]]</textarea>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "wms/income";
        $("#form-income-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-income-edit').serialize());
            }
        }

        $("input[name='createtime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function selectProductInfo() {
            var url = ctx + "main/product";
            var options = {
                title: '选择产品信息',
                height: "500",
                width: "800",
                url: url,
                callBack: doMaterialSubmit
            };
            $.modal.openOptions(options);
        }

        function doMaterialSubmit(index, layero){
            var rows = layero.find("iframe")[0].contentWindow.getProductSelections();

            if(rows <= 0){
                alert("请至少选择一条数据")
            }
            else {
                $("#ProductId").val(rows[0].id)
                $("#ProductName").val(rows[0].name)
                $("#ProductModel").val(rows[0].model)
                $.modal.close(index)
            }

        }

        function computedProductPrice() {
            var signalPrice = $("#signalPrice").val()
            var num = $("#num").val()

            $("#totalPrice").val(signalPrice*num)
        }

    </script>
</body>
</html>